<?php

class CHCSeries extends AbstractHCObject
{
    private $m_asPoint = array();
    
    /**
     * data  : Array<Mixed>  ""
     * An array of data points for the series. The points can be given in three ways:
     * 
     * 1. A numberical value ($pnX). In this case, the numberical value will be interpreted and y value, 
     * and x value will be automatically calculated, either starting at 0 and incrementing by 1, 
     * or from pointStart and pointInterval given in the plotOptions. 
     * If the axis is has categorie, it will be used. 
     * 
     * 2. A set of coordinates $pnX and $pnY : 
     * In this case, the first value is the x value and the second is the y value. 
     * 
     * 3. A complete point configuration ($pnX, $pnY, $psName, $psColor) 
     *  In this case the objects are point configuration objects as seen under options.point.
     *   
     * Moreover, the data can be given in any form if the dataParser 
     * function below is used to prepare the data and return in one of the 
     * 
     * @param Integer $pnX
     * @param Integer $pnY
     * @param String $psName
     * @param String $psColor
     */
    public function  addPoint($pnX, $pnY=null, $psName='', $psColor='')
    {
        if (CSDebug::assertNumber($pnX)) return false;
        
        $asPoint = array();
        
        $asPoint['x'] = $pnX;
        
        if (is_integer($pnY))
            $asPoint['y'] = $pnY;
            
        if (!empty($psName))
            $asPoint['name'] = $psName;
            
        if (!empty($psColor))
        {
            if (CSDebug::isHex($psColor))
                $asPoint['color'] = $psColor;
        }    
        
        if (count($asPoint) == 1)
            $this->m_asPoint[] = $pnX;
        else 
            $this->m_asPoint[] = $asPoint;
    }
    
    
    /**
     * Add all the data of the serie in an array
     * 
     * @param Array | mixed $pasArray
     */
    public function addDataSerie($pasArray)
    {
        if (CSDebug::assertArray($pasArray)) return false;
        
        foreach ($pasArray as $mData)
        {
            // multiple values
            if (is_array($mData))
            {
                $nCount = count($mData);
                switch ($nCount)
                {
                    case 1:
                      $this->addPoint($mData[0]);
                      break;

                    case 2: 
                      $this->addPoint($mData[0], $mData[1]);
                      break;  

                    case 3: 
                      $this->addPoint($mData[0], $mData[1], $mData[2]);
                      break;  

                    case 4: 
                      $this->addPoint($mData[0], $mData[1], $mData[2], $mData[3]);
                      break;  
                }
            }
            else 
            {
                $this->addPoint($mData);
            }
        }
    }
    
    
    /**
     * Callback function to parse the data given either through the data  or dataURL members. 
     * The data is passed as the first argument to the function. 
     * 
     * Return the parsed data in one of the forms given under data  above. 
     * 
     * @param $psString
     */
    public function setDataParser($psString)
    {
        if (CSDebug::assertString($psString)) return false;
        
        $this->setParam('dataParser', $psString);
    }
    
    
    /**
     *  The URL to a file to load the data using Ajax. 
     *  If the data is not in the form shown under data above, 
     *  it can be parsed using dataParser, 
     *  
     *  Defaults to null.
     *  
     * @param unknown_type $psString
     */
    public function setName($psString)
    {
        if ($psString == 'null' || is_null($psString)) return true;
        if (CSDebug::assertString($psString)) return false;
        
        $this->setParam('name', $psString);
    }
    
    /**
     *  The name of the series as shown in the legend, tooltip etc. Defaults to "".
     *  
     * @param String <URL> $psString
     */
    public function setDataUrl($psString='')
    {
        if (empty($psString)) return true;
        if (CSDebug::assertString($psString)) return false;
        
        $this->setParam('dataURL', $psString);
    }
    
    
    /**
     *   The type of series. Can be one of area, areaspline, bar, column, line, pie, scatter or spline. Defaults to "line". 
     *  
     *  Defaults to "".
     *  
     * @param $psString
     */
    public function setType($psString='line')
    {
        if (!in_array($psString, array('area', 'areaspline', 'bar', 'column', 'line', 'pie', 'scatter', 'spline'))) return false;
        
        $this->setParam('type', $psString);
    }
    
    
    /**
     *  When using dual or multiple x axes, this number 
     *  defines which xAxis the particular series is connected to. 
     *  It refers to the index of the axis in the xAxis array, 
     *  with 0 being the first. 
     *  
     *  Defaults to 0.
     *  
     * @param Integer $pnInteger
     */
    public function setXAxis($pnInteger)
    {
        if (CSDebug::assertInteger($pnInteger)) return false;
        
        $this->setParam('xAxis', $pnInteger);
    }
    
    
    /**
     *  When using dual or multiple y axes, 
     *  this number defines which yAxis the particular series is connected to. 
     *  It refers to the index of the axis in the yAxis array, with 0 being the first. 
     *  
     *  Defaults to 0.
     *  
     * @param Integer $pnInteger
     */
    public function setYAxis($pnInteger)
    {
        if (CSDebug::assertInteger($pnInteger)) return false;
        
        $this->setParam('yAxis', $pnInteger);
    }
    
    
    
    public function getData()
    {
        $this->setParam('data', $this->m_asPoint);
        
        return parent::getData();
    }
}

?>